package com.sd.controller;

import com.sd.entity.Log;
import com.sd.entity.PageBean;
import com.sd.entity.ReturnBean;
import com.sd.service.LogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Log)表控制层
 *
 * @author makejava
 * @since 2021-01-21 17:00:09
 */
@RestController
@RequestMapping("log")
public class LogController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private LogService logService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Log selectOne(Integer id) {
        return this.logService.queryById(id);
    }

    @GetMapping("insert")
    public Log insert(Log log) {
        return this.logService.insert(log);
    }


    /**
     * @create by : ydq
     * @description: 方法作用 ：查询全部
     * @create time : 2021/1/21 17:21
     */
    @GetMapping("selectAll")
    public ReturnBean selectAll (PageBean pageBean){
        int offset = getOffset(pageBean);
        List<Log> logList = logService.queryAllByLimit(offset, pageBean.getLimit());
        //返回json结果
        ReturnBean returnBean = returnSuccess(logList, logService.queryCount());
        return returnBean;
    }

}